package com.hiwan.report.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hiwan.report.pojo.FrSdrEntry;
import com.hiwan.report.pojo.FrSdrGroupEntry;
import com.hiwan.report.service.VideoReportService;
import com.hiwan.system.common.base.BaseController;
import com.hiwan.util.ExcelUtil;
import com.hiwan.util.FileUtil;

@Controller
@RequestMapping("/videoReport")
public class VideoReportAction extends BaseController{
	@Autowired
	private VideoReportService videoReportService;
	
	@RequestMapping("/toQueryGroup.do")
	public String toQueryGroup(ModelMap model,HttpSession session) {
		return "videoReport/queryGroup";
	}
	
	@RequestMapping("/toQueryDetail.do")
	public String toQueryDetail(ModelMap model,HttpSession session) {
		return "videoReport/queryDetail";
	}
	/**
	 * 查询视频详细列表方法
	 * @param model
	 * @param frSdrEntry
	 * @return
	 */
	@RequestMapping("/toList")
    public String toList(ModelMap model,FrSdrEntry frSdrEntry){
		List<FrSdrEntry> frSdrEntryList=videoReportService.selectVideoReports(frSdrEntry);
		model.put("frSdrEntryList", frSdrEntryList);
    	return "videoReport/detailList";
    }
	/**
	 * 导出视频详细信息列表方法
	 * @param frSdrEntry
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/toExpor")
	@ResponseBody
	public String toExpor(FrSdrEntry frSdrEntry,HttpServletRequest request,
			HttpServletResponse response){
		String msg="";
		ExcelUtil excelUtil = new ExcelUtil();
		List<FrSdrEntry> frSdrEntryList=videoReportService.selectVideoReports(frSdrEntry);
		String fileName = "视频报表明细.xls";
		excelUtil
				.writeListToExcel(
						frSdrEntryList,
						"视频报表明细",
						"orgId,custName,idType,idCard,loanContract,picFace,picIdCard,video,pathFace,pathIdCard,pathVideo,userId,similarity,matchResult,videoTime,videoSize,thumbnail,pathThumbnail",
						"所属机构,客户姓名,身份类型,身份证号码,贷款合同号,人脸照片文件,身份证照片文件,视频文件,人脸照片文件路径,身份证照片文件路径,视频文件路径 ,修改时间,人脸识别匹配相似度 ,人脸识别匹配结果 ,视频时长,视频大小KB,缩略图文件名,缩略图存储路径");

		try {
			FileUtil.downLoadFile(excelUtil.getFilePath(), fileName, request,response);
		} catch (Exception e) {
			e.printStackTrace();
			msg = "下载文件失败!<a href='#' onclick='javascript:history.go(-1);'>返回</a><br/>";
			msg += e.getMessage();
		}
		return msg;
	}
	
	/**
	 * 查询视频分组列表方法
	 * @param model
	 * @param frSdrEntry
	 * @return
	 */
	@RequestMapping("/toGroupList")
    public String toGroupList(ModelMap model,FrSdrEntry frSdrEntry){
		List<FrSdrGroupEntry> frSdrEntryList=videoReportService.selectVideoReportsGroup(frSdrEntry);
		model.put("frSdrEntryList", frSdrEntryList);
    	return "videoReport/groupList";
    }
	/**
	 * 导出视频分组信息列表方法
	 * @param frSdrEntry
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/toGroupExpor")
	@ResponseBody
	public String toGroupExpor(FrSdrEntry frSdrEntry,HttpServletRequest request,
			HttpServletResponse response){
		String msg="";
		ExcelUtil excelUtil = new ExcelUtil();
		List<FrSdrGroupEntry> frSdrEntryList=videoReportService.selectVideoReportsGroup(frSdrEntry);
		String fileName = "视频报表分组.xls";
		excelUtil
				.writeListToExcel(
						frSdrEntryList,
						"视频报表分组",
						"orgId,custName,idType,idCard,loanContract,sdrcount",
						"所属机构,客户姓名,身份类型,身份证号码,贷款合同号,视频个数");

		try {
			FileUtil.downLoadFile(excelUtil.getFilePath(), fileName, request,response);
		} catch (Exception e) {
			e.printStackTrace();
			msg = "下载文件失败!<a href='#' onclick='javascript:history.go(-1);'>返回</a><br/>";
			msg += e.getMessage();
		}
		return msg;
	}
}
